package main

import (
	"fmt"
	_ "time"
)

//
func main() {
	messages := make(chan string)
	msg := "hi"

	// go func() {
	// 	messages <- msg
	// }()

	// chan会阻塞一个goroutine，本例子只有一个goroutine，就是你的main,所以下面的代码会立刻阻塞导致死锁 all goroutines are asleep - deadlock!
	// 解决办法是放入缓冲chan或者在另一个协程(goroutine)中发送chan
	messages <- msg

	select {
	case msg2 := <-messages:
		fmt.Println("received message", msg2)
	default:
		fmt.Println("no message received")
	}
}
